package com.design.pattern.create.builder;

import com.design.pattern.entry.fruit.Apple;
import com.design.pattern.entry.fruit.Banana;
import com.design.pattern.entry.fruit.Orange;

/**
 * 水果套餐对象
 *
 * @author gyf
 * @create 2018-11-30 20:20
 **/
public class FruitMeal {
    private Apple apple;//苹果价格
    private Orange orange;//橘子价格
    private Banana banana;//香蕉价格
    private int discount;//折扣价
    private int totalPrice;//总价

    public void setApple(Apple apple) {
        this.apple = apple;
    }

    public void setOrange(Orange orange) {
        this.orange = orange;
    }

    public void setBanana(Banana banana) {
        this.banana = banana;
    }

    public int cost() {
        return this.totalPrice;
    }

    public void init() {
        if (apple != null) {
            totalPrice += apple.price();
        }
        if (orange != null) {
            totalPrice += orange.price();
        }
        if (banana != null) {
            totalPrice += banana.price();
        }
        if (totalPrice > 0) {
            totalPrice -= discount;
        }
    }

    public void setDiscount(int discount) {
        this.discount = discount;
    }

    public void showItems() {
        System.out.println("totalPrices:" + totalPrice);
    }
}
